
from collections import Counter
print("----" * 11)
L = []
a = "abcevaefegsgdghfdefavbdr"

# 办法1
print("统计a中各项的个数，办法1(字典):")
dist = {}
for i in a:
    dist[i] = a.count(i)
print(dist)

print("----" * 11)
# 办法2
print("统计a中各项的个数，办法2(collections的counter):")
print(Counter(a))


print("----" * 11)
# 办法3
print("统计a中各项的个数，办法3(count方法):")
for i in a:
    # print("%s:%d" %(i,a.count(i)))
    L.append(a.count(i))
L = list(set(L))
L.sort(reverse=True)
numl = []
for m in L:
    for n in a:
        if m == a.count(n):
            numl.append(n)
# 去重
num2 = []
for i in numl:
    if i not in num2:
        num2.append(i)


print(num2)


print("----" * 11)
# 办法4
print("统计a中各项的个数,办法4(列表count方法):")
dista = list(a)
print('dista:', dista)
for i in dista:
    print("%s:%d" % (i, dista.count(i)))


print("----" * 11)
a = input('请输入一串字符串:')
result = Counter(a)
print("----" * 11)
print(result)
b = sorted(result.items(), reverse=True)
b_max = result.most_common(3)
print("----" * 11)
print(b)
print("----" * 11)
print(b_max)

# 不使用内置函数实现下
# 输出要一目了然
